package com.gaojice.server.http.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.gaojice.server.constants.Constants;
import com.gaojice.server.http.model.FileItem;

public class FileItemService {
	public List<FileItem> getFileItems(String pathOnServer) {
		List<FileItem> fileItems = new ArrayList<FileItem>();
		String rootPath = Constants.ROOT_DIR + "/" + pathOnServer;
		File root = new File(rootPath);
		for (File file : root.listFiles()) {
			FileItem fileItem = new FileItem();
			fileItem.setIsFile(file.isFile());
			fileItem.setName(file.getName());
			if (pathOnServer.equals("/")) {
				pathOnServer = "";
			}
			fileItem.setLink(pathOnServer + "/" + fileItem.getName());
			fileItems.add(fileItem);
		}
		return fileItems;
	}
}
